package com.ala4.oxcafe.repository.mapper;

import com.ala4.oxcafe.entity.MenuInfo;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * 菜单信息
 *
 * @author PING
 * @version 1.0.0
 * @date 2025/8/12 12:44
 */
public interface MenuInfoMapper extends BaseMapper<MenuInfo> {

    @Select("select DISTINCT t.* from menu_info t " +
            "left join role_menu_rel m on t.id = m.menu_id " +
            "left join user_role_rel u on u.role_id = m.role_id " +
            "where u.user_id = #{userId}")
    List<MenuInfo> selectUserMenu(@Param("userId") Long userId);

    @Select("SELECT max(id) FROM menu_info t " +
            "where t.parent_id = #{parentId} and t.del_flag in (0,1)")
    Long selectMaxIdMenu(@Param("parentId") Long parentId);

    @Select("select DISTINCT m.menu_path from role_menu_rel m " +
            "left join user_role_rel u on u.role_id = m.role_id " +
            "where m.menu_path is not null and u.user_id = #{userId}")
    List<String> selectUserMenuV2(Long userId);

}
